class Solution(object):
    def countPairs(self, nums1, nums2):
        n = len(nums1)
        diff = [nums1[i] - nums2[i] for i in range(n)]
        diff.sort()
        left = 0
        right = n - 1
        ans = 0
        while left < right:
            if diff[left] + diff[right] > 0:
                ans += right - left
                right -= 1
            else:
                left += 1
        return ans